
//设置当前日期
function setCurrentDate()
{
    var nowDay = new Date()
    var week = new Array(7);
    week[0] = '日';
    week[1] = '一';
    week[2] = '二';
    week[3] = '三';
    week[4] = '四';
    week[5] = '五';
    week[6] = '六';
    var temp = '今日：';
    temp += '星期' + week[nowDay.getDay()] + '';
    temp += ' ' + nowDay.getFullYear() + '年' + (nowDay.getMonth() + 1) + '月' + nowDay.getDate() + '日';
    temp += ' ';
    $('#currentDate').html(temp);
}

//设置当前时间
function setCurrentTime()
{
    var nowDay = new Date()
    var temp = nowDay.toLocaleTimeString();

    $('#currentTime').html(temp);
    setTimeout(setCurrentTime, 1000);
}

Tool = {
    alert: function(msg)
    {
        $.messager.alert('系统提示',msg,'warning');
    },

    show: function(msg)
    {
		$.messager.alert('系统提示',msg,'info');
    },

    alertError: function(msg)
    {
        if (msg == undefined || msg == "")
        {
            msg = '操作失败 请稍后重试'
        }
		$.messager.alert('系统提示',msg,'error');
    },

    _createBox: function(t, s)
    {
        return '<div class="msg"><h3>' + t + '</h3><p>' + s + '</p></div>';
    },

//    hint: function(title, format)
//    {
//        if (!this.msgCt) {
//            this.msgCt = Ext.DomHelper.insertFirst(document.body, {
//                id:'msg-div'
//            }, true);
//        }
//        var s = Ext.String.format.apply(String, Array.prototype.slice.call(arguments, 1));
//        var m = Ext.DomHelper.append(this.msgCt, this._createBox(title, s), true);
//        m.hide();
//        m.slideIn('t').ghost("t", {
//            delay: 1000,
//            remove: true
//        });
//    },

    post: function(params, url, callback, scope)
    {

        this.ajaxRun(params, url, callback, scope, "Post");
    },

    request: function(params, url, callback, scope)
    {
        this.ajaxRun(params, url, callback, scope, "GET");
    },

    ajaxRun: function(params, url, callback, scope, method)
    {
        var debug = this.debug;
        $.ajax(
        {
            url: url,
            method: method,
            data: params,
            scope: this,
            success: function(response, options)
            {
                var result = eval("(" +response+")");
                if (result.success)
                {
                    var msg = "操作成功！";
                    if (result.msg != undefined && result.msg != "")
                    {
                        msg = result.msg;
                    }

                    if (typeof result.noalert == 'undefined'){
                        Tool.show(msg);
                    //this.hint("系统提示", msg);
                    }

                    if (callback != undefined)
                    {
                        callback.call(scope, result);
                    }
                }
                else
                {

				Tool.alertError(result.msg);
                }
            },
            failure: function(response, options)
            {
                //此处记录异常日志
                var msg = response.responseText;

                this.alertError(msg);
            }
        });
    },

    delRequest: function(params, url, callback, scope){
        $.messager.confirm('系统提示', '确定删除选中的项目？', function(r){
			if(r) {
                Tool.request(params, url, callback, scope);
            }
        },this);
    },
	moveRequest: function(params, url, callback, scope){
        $.messager.confirm('系统提示', '确定选中的项目？', function(btn){
            if(btn == "yes") {
                this.request(params, url, callback, scope);
            }
        }, this);
    }

};
//changePassword为DIV    passwordForm为表单（）
function changePassword() {
        $('#changePassword').dialog({
            title:'Dialog',
            width:350,
            height:180,
            closed:false,
            title:'修改密码',
            modal:true,
        });
}
//验证重复输入密码是否一致
$.extend($.fn.validatebox.defaults.rules, {
/*必须和某个字段相等*/
    equalTo: {
        validator:function(value,param){
            return $(param[0]).val() == value;
        },
        message:'字段不匹配'
    }
});

//格式化显示下拉框数据
function formatComboboxItem(row) {
    var s = '<span style="font-weight:bold">' + row.text + '</span><br/>';
    return s;
}
//提交表单成功后刷新grid一类
function submitForm(form_id,url,win_id,grid_id) {
    $('#'+form_id).form('submit',{
    method:'POST',
    url: url,
    success:function(data){
        var data = eval("data =" +data);
        if (data.success)
        {
            $.messager.alert('系统提示','操作成功','info');
            $('#'+win_id).dialog('close');
            $('#'+grid_id).datagrid('reload');
        }
        else
        {
            $.messager.alert('系统提示','操作失败','error');
        }
    }
});
}
function mysubmit() {
  if($('#passwordForm').form('validate')){
       $('#passwordForm').form('submit',{
        success:function(meg){
            if(meg == '修改成功'){
                $.messager.alert('提示','修改成功!');
                $('#changePassword').dialog('close');
                $('#passwordForm').form('clear');
            }else{
                $('#error_password').text('密码错误');
            }
        }
       });
  }
}
function cleardata(){
    $('#passwordForm').form('clear');
    $('#error_password').text('');
}



//验证密码是否一致
$.extend($.fn.validatebox.defaults.rules, {
    equals: {
        validator: function(value,param){
            return value == $(param[0]).val();
        },
        message: '两次密码不一致'
    }
});
//限定输入最少长度
$.extend($.fn.validatebox.defaults.rules, {
    minLength: {
        validator: function(value, param){
            return value.length >= param[0];
        },
        message: '请输入至少{0}个字符'
    }
});
